#include<stack>
#include<algorithm>
using std::min;
using std::stack;

class MinStack {
public:
    stack<int> myStack; 
    stack<int> minStack;
    MinStack() {
        
    }
    
    void push(int val) {
        if (myStack.empty()) {
            minStack.push(val);
            myStack.push(val);
            return;
        }
        
        myStack.push(val);
        minStack.push(min(val, minStack.top()));
    }
    
    void pop() {
        if (!myStack.empty()) {
            myStack.pop();
            minStack.pop();
        }
    }
    
    int top() {
        return myStack.top();
    }
    
    int getMin() {
        return minStack.top();
    }
};